package L615;

import java.util.Random;

/**
 * @program: javase
 * @description:
 * @author: luolidong
 * @create: 2021-06-15 10:34
 * @version: 1.0
 */
public class Demo1 {
    public int merge(int[] arr,int left,int right){
        if(left==right) return arr[left];
        int mid=(left+right)/2;
        int l1=merge(arr, left, mid);
        int l2=merge(arr, mid+1, right);
        return sum(l1,l2);

    }
    public int sum(int l1,int l2){
        return l1+l2;
    }

    public static void main(String[] args) {
        int[] ints = new int[100001];
        for (int i = 0; i < 100000; i++) {
            ints[i]=new Random().nextInt(100000);
        }
        long l = System.currentTimeMillis();
        int merge = new Demo1().merge(ints, 0, ints.length-1);
        long l1 = System.currentTimeMillis();
        System.out.println((l1-l)+":merge = " + merge);

        long l2 = System.currentTimeMillis();
        int sum=0;
        for (int i = 0; i < ints.length; i++) {
            sum+=ints[i];
        }
        long l3 = System.currentTimeMillis();
        System.out.println((l3-l2)+":normal = " + sum);
    }
}
